package com.zoro.barn.business.service.pp.business.projectproduct.controller;

import com.zoro.barn.business.service.pp.business.product.entity.BarnProduct;
import com.zoro.barn.business.service.pp.business.project.entity.BarnProject;
import com.zoro.barn.business.service.pp.business.projectproduct.controller.dto.AddProductDto;
import com.zoro.barn.business.service.pp.business.projectproduct.entity.BarnProjectProduct;
import com.zoro.barn.business.service.pp.business.projectproduct.service.BarnProjectProductService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhaoxingwu
 */
@RestController
@RequestMapping("/project-product")
public class ProjectProductController {

    private final BarnProjectProductService barnProjectProductService;

    public ProjectProductController(BarnProjectProductService barnProjectProductService) {
        this.barnProjectProductService = barnProjectProductService;
    }


    @RequestMapping("/projectAddProducts")
    public void projectAddProducts(@RequestBody AddProductDto dto) {
        this.barnProjectProductService.insertBatch(dto.getProjectId(), dto.getProductIds());
    }

    @RequestMapping("/getProductByProject/{projectId}")
    public List<BarnProduct> getProductByProject(@PathVariable String projectId) {
        return this.barnProjectProductService.getByProject(projectId);
    }

    @RequestMapping("/getProjectByProduct/{productId}")
    public List<BarnProject> getProjectByProduct(@PathVariable String productId) {
        return this.barnProjectProductService.getByProduct(productId);
    }

    @RequestMapping("/delete")
    public void delete(@RequestBody BarnProjectProduct projectProduct) {
        this.barnProjectProductService.delete(projectProduct.getProjectId(), projectProduct.getProductId());
    }
}
